﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace duanzhi.web.Models
{
    public class article:MongoDocument
    {
        [BsonElement("T")]
        public string title { set; get; }
        [BsonElement("C")]
        public string content { set; get; }
        /// <summary>
        /// 用户ID
        /// </summary>
        [BsonElement("UI")]
        public ObjectId userID{set;get;}
        /// <summary>
        /// 用户名
        /// </summary>
        [BsonElement("UN")]
        public string userName { set; get; }
        /// <summary>
        /// 回复
        /// </summary>
        [BsonElement("R")]
        public List<reply> reply {set;get;}
        [BsonElement("TS")]
        public List<string> tags { set; get; }
        [BsonElement("D")]
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime datetime { set; get; }
        [BsonElement("LD")]
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime lastDatetime { set; get; }
        /// <summary>
        /// 推荐数
        /// </summary>
        [BsonElement("RC")]
        public int recommend { set; get; }
        /// <summary>
        /// 原作者
        /// </summary>
        [BsonElement("A")]
        public string author { set; get; }
        /// <summary>
        /// 来至
        /// </summary>
        [BsonElement("F")]
        public string from { set; get; }
        /// <summary>
        /// 扩展url
        /// </summary>
        [BsonElement("E")]
        public string extUrl { set; get; }
        /// <summary>
        /// 发布
        /// </summary>
        [BsonElement("RL")]
        public Boolean release { set; get; }
        /// <summary>
        /// 类型
        /// </summary>
        public int type { set; get; }
        /// <summary>
        /// 置顶
        /// </summary>
        public Boolean Top { set; get; }
        [BsonElement("DA")]
        public Boolean disable { set; get; }
    }
    public enum articleType {
        段子=1,
        图片=2,
        语录=3,
    }

    public class reply:MongoDocument{
        [BsonElement("C")]
        public string content { set; get; }
        [BsonElement("UI")]
        public ObjectId userID { set; get; }
        [BsonElement("UN")]
        public string userName { set; get; }
        [BsonElement("D")]
        public DateTime datetime { set; get; }
    }
    public class tag : MongoDocument {
        [BsonElement("N")]
        [BsonRequired]
        public string name { set; get; }
        [BsonElement("I")]
        [BsonDefaultValue(0)]
        public int index { set; get; }
    }
    public class type : MongoDocument {
        [BsonElement("N")]
        [BsonRequired]
        public string name { set; get; } 
    }
    public partial class user:MongoDocument {
        public string name {set;get; }
        public string password {set;get; }
    }
    public partial class user {

        public static user guest
        {
            get
            {
                DataSession<MongoDataContext, user> db = new DataSession<MongoDataContext, user>();
                var u = db.GetById(ObjectId.Parse("000000000000000000000001"));
                if (u == null)
                {
                    u = new user() { Id = ObjectId.Parse("000000000000000000000001"), name = "匿名用户" };
                    db.Save(u);
                }

                return u;
            }
        }
        public static user login {get{
            return guest;
        } }
    }
}